package com.sky.demo.activities;

import android.animation.ObjectAnimator;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.sky.demo.R;
import com.sky.demo.dialog.DialogManager;
import com.sky.demo.global.BaseActivity;
import com.sky.demo.utils.ToastUtils;
import com.sky.demo.views.FlowLayout;
/**
 * @ClassName: IntroductoryActivity
 * @Description: TODO 流式布局
 * @author LiBin
 * @date 2015年3月26日 下午4:01:00
 */
public class FlowActivity extends BaseActivity implements View.OnClickListener {
    private String[] mVals = new String[]
            {"Hello", "Android", "Weclome Hi ", "Button", "TextView", "Hello",
                    "Android", "Weclome", "Button ImageView", "TextView", "Helloworld",
                    "Android", "Weclome Hello", "Button Text", "TextView"};

    private FlowLayout mFlowLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_flow);

        mFlowLayout = (FlowLayout) findViewById(R.id.id_flowlayout);

        initData();
    }

    public void initData() {
        LayoutInflater mInflater = LayoutInflater.from(this);
        for (int i = 0; i < mVals.length; i++) {
            TextView tv = (TextView) mInflater.inflate(R.layout.tv,
                    mFlowLayout, false);
            ViewGroup.LayoutParams lp = tv.getLayoutParams();
            lp.width = ViewGroup.LayoutParams.WRAP_CONTENT;
            tv.setLayoutParams(lp);
            tv.setText(mVals[i]);
            mFlowLayout.addView(tv);
//            ObjectAnimator.ofFloat(tv, "rotation", 0F, 360F).setDuration(3000).start();
            tv.setTag(mVals[i]);
            tv.setOnClickListener(this);
        }
        for (int i = 'A'; i <= 'z'; i++) {
            TextView tv = (TextView) mInflater.inflate(R.layout.tv, mFlowLayout, false);
            tv.setText((char) i + "");
            mFlowLayout.addView(tv);
            ObjectAnimator.ofFloat(tv, "rotation", 0F, 360F).setDuration(3000).start();
            setOnclicK(tv);
        }


    }

    private void setOnclicK(final TextView tv) {
        tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Dialog dialog = DialogManager.createDialog(FlowActivity.this);
                dialog.setCancelable(true);
                dialog.show();
                showToast(tv.getText().toString());
            }
        });
    }


    @Override
    public void onClick(View v) {
        String tag= (String) v.getTag();
        if (tag.equals(mVals[0])){
            ToastUtils.showShort(this,mVals[0]);
            startActivity(new Intent(FlowActivity.this, LoginActivity.class));
        }else {
            startActivity(new Intent(FlowActivity.this, PullDownActivity.class));
        }
    }
}
